<template>
  <div class="page-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>黑马面经运营后台</span>
      </div>
      <!-- 表单 -->
      <el-form
        ref="form"
        :rules="rules"
        label-position="top"
        autocomplete="off"
        :model="user"
      >
        <el-form-item label="用户名" prop="username">
          <el-input v-model="user.username" placeholder="输入用户名"></el-input>
        </el-form-item>

        <el-form-item label="密码" prop="password">
          <el-input
            type="password"
            v-model="user.password"
            placeholder="输入用户密码"
          ></el-input>
        </el-form-item>

        <el-form class="tc">
          <el-button type="primary" @click="login">登 录</el-button>
          <el-button @click="reset">重 置</el-button>
        </el-form>
      </el-form>
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      user: {
        username: '',
        password: '',
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
        ],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
      },
    };
  },
  // 验证登录和重置按钮
  methods: {
    async login() {
      await this.$refs.form.validate();
      console.log('校验通过');
      // 调用登录action
      this.$store.dispatch('user/login', this.user);
    },
    reset() {
      this.$refs.form.resetFields();
    },
  },
};
</script>
<style scoped>
.page-container {
  display: flex;
  height: 100vh;
  justify-content: center;
  align-items: center;
  background-image: url("@/assets/login-bg.svg");
  background-size: 100% 100%;
  background-repeat: no-repeat;
}

.box-card {
  width: 33%;
  border: 0;
}

::v-deep .el-card__header {
  background-color: #727cf5;
  text-align: center;
  color: #fff;
}

.tc {
  text-align: center;
}
</style>
